﻿using Coldairarrow.Business;
using Coldairarrow.Entity.BaseConfig;
using Coldairarrow.Util.Helper;
using EFCore.Sharding;
using System.Collections.Generic;
using System.Linq;

namespace Coldairarrow.Util.Config
{

    public  class ConfigsService : BaseBusiness<Base_SysConfig>,IConfigsService, ITransientDependency
    {
        string Key = "xazkrj68018948";
        public ConfigsService(IDbAccessor repository)
            : base(repository)
        {

        }

       private  List<Base_SysConfig> GetConfigList()
       {
            if (ConfigList.List == null || ConfigList.List.Count == 0)
            {
                ConfigList.List =   GetIQueryable().ToList();
            }
            return ConfigList.List;
        }


       public string GetKeyValue(string key)
        {
            string value = "";
            List<Base_SysConfig> cList = GetConfigList();
            var sModel = cList.Where(x => x.KeyName.Equals(key)).FirstOrDefault();
            if (!sModel.IsNullOrEmpty())
            {
                value = sModel.KeyValue;
                if (!value.IsNullOrEmpty())
                {
                    value = AESHelper.AesDecrypt(value);
                }
            }

            return value;
        }

       public void Clear()
        {
            ConfigList.List = null;
        }
    }
}
